<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('待本部门回复M')"/>
    <link th:href="@{/ajax/libs/bootstrap-switch/bootstrap-switch.min.css}" rel="stylesheet">
</head>
<style>
    .smsnote {
        display: flex;
        flex-direction: row;
        justify-content: flex-start;
    }
    .modal {
        width:100%;
        top: 50%;
        left: 60%;
        transform: translate(-50%, -50%);
    }
</style>
<body class="gray-bg">
<div class="container-div">
    <div class="row">
        <div class="col-sm-12 search-collapse">
            <form id="post-form">
                <input type="hidden" name="areaNo" id="areaNo" th:value="${sysUser.areaNo}">
                <div class="select-list">
                    <ul>
                        <li>
                            工单编号：<input type="text" name="workFormNO"/>
                        </li>
                        <li>
                            派发单位：<input type="text" name="sdeptName"/>
                        </li>
                        <li>
                            信件来源：<input type="text" name="spareString"/>
                        </li>
                        <li>
                            下级回复：<select name="backDesc">
                                        <option value="">全部</option>
                                        <option value="已回复">已回复</option>
                                        <option value="未全回">未全回</option>
                                        <option value="全退">全退</option>
                                        <option value="0">未回复</option>
                                    </select>
                        </li>
                        <li class="select-time">
                            <label>办理期限： </label>
                            <input type="text" class="time-input mr10" id="startTime" placeholder="开始时间"
                                   name="beginTime"/>
                            <input type="text" class="time-input" id="endTime" placeholder="结束时间"
                                   name="endTime"/>
                        </li>
                        <li>
                            催办件：<select name="formType">
                            <option value="">请选择</option>
                            <option value="1">催办件</option>
                        </select>
                        </li>
                        <li>
                            <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i
                                    class="fa fa-search"></i>&nbsp;搜索</a>
                            <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i
                                    class="fa fa-refresh"></i>&nbsp;重置</a>
                            <a class="btn btn-info btn-rounded btn-sm" onclick="sameSearch()"><i
                                    class="fa fa-send"></i>&nbsp;同源再派</a>
                        </li>
                    </ul>
                </div>
            </form>
        </div>

        <div class="btn-group-sm " id="toolbar" role="group">
            <a class="btn btn-success single disabled" onclick="reply()">
                <i class="fa"></i> 回复
            </a>
            <a class="btn btn-primary single disabled" onclick="postpone()">
                <i class="fa"></i> 延期
            </a>
            <a class="btn btn-danger multiple disabled" onclick="Return()">
                <i class="fa"></i> 退回
            </a>
            <a class="btn btn-success multiple disabled" onclick="printX()">
                <i class="fa fa-print"></i> 转办单
            </a>
            <a class="btn btn-primary multiple disabled" onclick="postponeBatch()">
                <i class="fa"></i> 批量延期
            </a>
            <a class="btn btn-danger multiple disabled" onclick="urgeTransact()">
                <i class="fa"></i> 催办
            </a>
            <a class="btn btn-info" onclick="exportReplyWaitExcel()">
                <i class="fa fa-download"></i> 导出
            </a>
        </div>

        <div class="col-sm-12 select-table table-striped">
            <table id="bootstrap-table"></table>
        </div>

        <div class="modal" id="smsInformModal" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
            <div class="modal-dialog" role="document">
                <div class="modal-content" style="width: 320px;">
                    <div class="modal-header" style="height: 42px;">
                        <h5 style="font-size: 14px">确认催办所选工单？</h5>
                        <button type="button" class="close" style="margin-top: -30px;" data-dismiss="modal" aria-label="Close">
                            <span aria-hidden="true">&times;</span>
                        </button>
                    </div>
                    <div class="modal-body">
                        <div class="smsnote">
                            <label style="width: 120px;color: #1453dc;">是否开启短信通知：</label>
                            <div>
                                <input type="checkbox" name="smsInform">
                            </div>
                            <input type="hidden" id="smsInform" value="0">
                        </div>
                    </div>
                    <div class="modal-footer">
                        <button type="button" class="btn btn-primary" onclick="ackTransact()">确认</button>
                        <button type="button" class="btn btn-secondary" data-dismiss="modal">取消</button>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
<th:block th:include="include :: footer"/>
<script th:src="@{/ajax/libs/bootstrap-switch/bootstrap-switch.min.js}"></script>
<script th:inline="javascript">
    var prefix = ctx + "system/mMailWF";
    var cmnTab = ctx + "system/cmnTab";
    var mInterior = ctx + "system/mInterior";

    function printX() {
        var url = prefix+"/forShow/printSends";
        let row = $("#bootstrap-table").bootstrapTable('getSelections');
        if (row.length < 2) {
            url += "?ids="+row[0].myPkVal;
        }else {
            var ids = '';
            for (let i = 0; i < row.length; i++) {
                ids += row[i].myPkVal;
                if ((i+1) != row.length) {
                    ids += ","
                }
            }
            url += "?ids="+ids;
        }
        window.open(url,"printX",'left=100,top=20,height=700,width=720,toolbar=yes,menubar=yes,scrollbars=auto');

    }

    $(function () {
        let options = {};
        let areaNo = $("#areaNo").val();
        if (areaNo === '510109'){
            options = {
                url: prefix + "/cmnFile/replyWaitJson_gxq",
                sortName: "myPkVal",
                updateUrl: prefix + "/cmnFile/dlReplyS/{id}",
                sortOrder: "desc",
                uniqueId: "myPkVal",
                modalName: "待本部门回复",
                fixedColumns: true,
                fixedNumber: 1,
                fixedRightNumber: 1,
                rowStyle: rowStyle,
                showFooter: true,
                onLoadSuccess:function (data) {
                    dueWorkOrder(data)
                },
                columns: [{
                    checkbox: true
                },
                    {field: '', title: '序号', align: "center", width: 40,formatter:function(value,row,index){return serialNumber(value,row,index);}},
                    {field:'myPkVal',title:'pkid',visible:false},
                    {field:'WfId',title:'WfId',visible:false},
                    {field:'OriLevel',title:'OriLevel',visible:false},
                    {field:'fmDept',title:'fmDept',visible:false},
                    {field:'sbDept',title:'sbDept',visible:false},
                    {field:'SendState',title:'SendState',visible:false},
                    {field:'myMwfNO',title:'工单编号',align:'center',halign:'center'},
                    {field:'SpareString',title:'信件来源',align:'center',halign:'center',sortable:true, formatter:function(value,row,index) {
                            return value == '互联网+督查' ? '<span style="color:#ff0000;">'+value+'</span>' : value;
                        }},
                    {field:'myMwfTopic',title:'工单主题',align:'center',halign:'center',formatter:function (value, row, index,field) {
                            var obj = rowStyle(row)
                            if(obj == '')
                                return "<span style='cursor: pointer;' title='"+value+"'>"+value+"</span>"
                            if(obj.css.color == 'blue')
                                return "<span style='cursor: pointer;color: blue;font-weight: bold;' title='"+value+"'>"+value+"</span>"
                            else if(obj.css.color == 'red')
                                return "<span style='cursor: pointer;color: red;font-weight: bold;' title='"+value+"'>"+value+"</span>"
                            else if(obj.css.color == 'darkcyan')
                                return "<span style='cursor: pointer;color: darkcyan;font-weight: bold;' title='"+value+"'>"+value+"</span>"
                        },
                        cellStyle: cellEllipsis
                    },
                    {field: 'FmContent', title: '工单内容', align: 'center',formatter:function (value, row, index,field) {
                            var obj = rowStyle(row)
                            if(obj == '')
                                return "<span style='cursor: pointer;' title='"+value+"'>"+value+"</span>"
                            if(obj.css.color == 'blue')
                                return "<span style='cursor: pointer;color: blue;font-weight: bold;' title='"+value+"'>"+value+"</span>"
                            else if(obj.css.color == 'red')
                                return "<span style='cursor: pointer;color: red;font-weight: bold;' title='"+value+"'>"+value+"</span>"
                            else if(obj.css.color == 'darkcyan')
                                return "<span style='cursor: pointer;color: darkcyan;font-weight: bold;' title='"+value+"'>"+value+"</span>"
                        },
                        cellStyle: cellEllipsis
                    },
                    {field: 'dCntAName1', title: '内容类别（一级）', align: 'center'},
                    {field: 'dCntAName2', title: '内容类别（二级）', align: 'center'},
                    {field: 'dCntAName3', title: '内容类别（三级）', align: 'center'},
                    {field:'SeqName',title:'交办次序',align:'center',sortable:true},
                    {field:'SortName',title:'性质',align:'center',sortable:true},
                    {field:'DealName',title:'办理方式',align:'center',sortable:true},
                    {field:'bkLimit',title:'办理期限',align:'center',sortable: true},
                    {field:'SDeptName',title:'派发单位',align:'center',halign:'center',sortable:true},
                    {field:'acDate',title:'签收日期',align:'center'},
                    {field:'bkState',title:'审查标记',align:'center',formatter:function(value,row,index){return fmtSBBackState(value,row,index);}},
                    {field:'acRemark',title:'备注',align:'center',halign:'center',
                        formatter:function (value, row, index,field) {
                            if(value==undefined){
                                value='';
                            }
                            return "<span style='cursor: pointer;' title='"+value+"'>"+value+"</span>"
                        },
                        cellStyle: cellEllipsis
                    },
                    {field:'cbackDesc',title:'下级回复',align:'center',sortable:true},
                    {field:'FlagString',title:'转办情况',align:'center',halign:'center',sortable:true},
                    {
                        field:'dueCount',
                        title: '操作',
                        align: 'center',
                        formatter: function (value, row, index) {
                            var actions = [];
                            if (row.SendState === 40){
                                actions.push('<a class="btn btn-done btn-xs " href="javascript:void(0)")"><i class="fa"></i>退回件</a>')
                            }else{
                                actions.push('<a class="btn btn-success btn-xs " href="javascript:void(0)" onclick="reply('+row.WfId+','+row.myPkVal+')"><i class="fa"></i>回复</a>');
                            }
                            return actions.join('');
                        },footerFormatter:function (value, row, index) {return dueWorkOrderCount(value, row, index)}
                    }]
            };
        }else {
            options = {
                url: prefix + "/cmnFile/replyWaitJson",
                sortName: "myPkVal",
                updateUrl: prefix + "/cmnFile/dlReplyS/{id}",
                sortOrder: "desc",
                uniqueId: "myPkVal",
                modalName: "待本部门回复",
                fixedColumns: true,
                fixedNumber: 1,
                fixedRightNumber: 1,
                rowStyle: rowStyle,
                columns: [{
                    checkbox: true
                },
                    {field: 'myPkVal', title: 'pkid', visible: false},
                    {field: 'WfId', title: 'WfId', visible: false},
                    {field: 'OriLevel', title: 'OriLevel', visible: false},
                    {field: 'fmDept', title: 'fmDept', visible: false},
                    {field: 'sbDept', title: 'sbDept', visible: false},
                    {field: 'myMwfNO', title: '工单编号', align: 'center', halign: 'center'},
                    {
                        field: 'SpareString',
                        title: '信件来源',
                        align: 'center',
                        halign: 'center',
                        sortable: true,
                        formatter: function (value, row, index) {
                            return value == '互联网+督查' ? '<span style="color:#ff0000;">' + value + '</span>' : value;
                        }
                    },
                    {
                        field: 'myMwfTopic',
                        title: '工单主题',
                        align: 'center',
                        halign: 'center',
                        formatter: function (value, row, index, field) {
                            var obj = rowStyle(row)
                            if (obj == '')
                                return "<span style='cursor: pointer;' title='" + value + "'>" + value + "</span>"
                            if (obj.css.color == 'blue')
                                return "<span style='cursor: pointer;color: blue;font-weight: bold;' title='" + value + "'>" + value + "</span>"
                            else if (obj.css.color == 'red')
                                return "<span style='cursor: pointer;color: red;font-weight: bold;' title='" + value + "'>" + value + "</span>"
                            else if (obj.css.color == 'darkcyan')
                                return "<span style='cursor: pointer;color: darkcyan;font-weight: bold;' title='" + value + "'>" + value + "</span>"
                        },
                        cellStyle: cellEllipsis
                    },
                    {
                        field: 'FmContent',
                        title: '工单内容',
                        align: 'center',
                        formatter: function (value, row, index, field) {
                            var obj = rowStyle(row)
                            if (obj == '')
                                return "<span style='cursor: pointer;' title='" + value + "'>" + value + "</span>"
                            if (obj.css.color == 'blue')
                                return "<span style='cursor: pointer;color: blue;font-weight: bold;' title='" + value + "'>" + value + "</span>"
                            else if (obj.css.color == 'red')
                                return "<span style='cursor: pointer;color: red;font-weight: bold;' title='" + value + "'>" + value + "</span>"
                            else if (obj.css.color == 'darkcyan')
                                return "<span style='cursor: pointer;color: darkcyan;font-weight: bold;' title='" + value + "'>" + value + "</span>"
                        },
                        cellStyle: cellEllipsis
                    },
                    {field: 'dCntAName1', title: '内容类别（一级）', align: 'center'},
                    {field: 'dCntAName2', title: '内容类别（二级）', align: 'center'},
                    {field: 'dCntAName3', title: '内容类别（三级）', align: 'center'},
                    {field: 'SeqName', title: '交办次序', align: 'center', sortable: true},
                    {field: 'SortName', title: '性质', align: 'center', sortable: true},
                    {field: 'DealName', title: '办理方式', align: 'center', sortable: true},
                    {field: 'bkLimit', title: '办理期限', align: 'center', sortable: true},
                    {field: 'SDeptName', title: '派发单位', align: 'center', halign: 'center', sortable: true},
                    {field: 'acDate', title: '签收日期', align: 'center'},
                    {
                        field: 'bkState', title: '审查标记', align: 'center', formatter: function (value, row, index) {
                            return fmtSBBackState(value, row, index);
                        }
                    },
                    {
                        field: 'acRemark', title: '备注', align: 'center', halign: 'center',
                        formatter: function (value, row, index, field) {
                            if (value == undefined) {
                                value = '';
                            }
                            return "<span style='cursor: pointer;' title='" + value + "'>" + value + "</span>"
                        },
                        cellStyle: cellEllipsis
                    },
                    {field: 'cbackDesc', title: '下级回复', align: 'center', sortable: true},
                    {field: 'FlagString', title: '转办情况', align: 'center', halign: 'center', sortable: true},
                    {
                        title: '操作',
                        align: 'center',
                        formatter: function (value, row, index) {
                            var actions = [];
                            actions.push('<a class="btn btn-success btn-xs " href="javascript:void(0)" onclick="reply(' + row.WfId + ',' + row.myPkVal + ')"><i class="fa"></i>回复</a>');
                            return actions.join('');
                        }
                    }]
            };
        }
        $.table.init(options);
    });

    //延期？单选（进入延期列表）：多选（批量延期）
    function postpone(){
        let row = $("#bootstrap-table").bootstrapTable('getSelections');
        if(row[0].SendState === 40){
            return $.modal.msgError('此工单已退回!')
        }
        var wfId = row[0].WfId;
        var sendId = row[0].myPkVal;
        if (wfId && sendId) {
            var url = mInterior + "/cmnFile/mwfDeferList?wfId="+wfId+"&sendId="+sendId;
            $.modal.openTab('延期申请情况',url);
        }
    }

    function postponeBatch(){
        let row = $("#bootstrap-table").bootstrapTable('getSelections');
        var ids = "";
        $.each(row,function(index,value){
            ids += row[index].myPkVal + ",";
        })
        ids = ids.substr(0,ids.length - 1);
        var url = mInterior + "/cmnFile/mDeferBatchAdd?ids="+ids;
        var title = '批量延期';
        var width = "500px";
        var height = "500px";
        var options = {
            url: url,
            title: title,
            width: width,
            height: height,
            btnArr: []
        }
        winDialog(options);
    }

    function reply(wfId,sendId){
        if (!(wfId && sendId)) {
            let row = $("#bootstrap-table").bootstrapTable('getSelections');
            if(row.length > 0 && row[0].SendState === 40){
                return $.modal.msgError('此工单已退回!')
            }
            var wfId = row[0].WfId;
            var sendId = row[0].myPkVal;
        }
        var url = cmnTab + "/mwfCReplyS/"+sendId+"?wfId="+wfId;
        $.modal.openTab('回复信件工单',url);
    }

    function Return(){
        let row = $("#bootstrap-table").bootstrapTable('getSelections');
        if(row.length > 0 && row[0].SendState === 40){
            return $.modal.msgError('此工单已退回!')
        }
        var sendId = row[0].myPkVal;
        var url = prefix + "/cmnFile/dlBackS/"+sendId;
        $.modal.openTab('退回信件工单',url);
    }

    function fmtBackState(value,row,index) {
        var wfid = row.WfId;
        var sdeptId = row.sbDept;
        var str = '';
        $.ajax({
            type: 'post',
            data: {wfId: wfid, sdeptId: sdeptId},
            dataType: 'json',
            async: false,
            url: '/system/mMailWF/forShow/checkSendBack',
            success: function (result) {
                str = result.backDesc;
            }
        });
        return str;
    }

    function sameSearch(){
        var btn = ['<i class="fa fa-check"></i> 同源再派', '<i class="fa fa-close"></i> 取消派单'];
        var options = {
            width: '75%',
            height: '90%',
            title: '同源再派',
            url: prefix + "/cmnFile/searchReplyForm",
            btn: btn,
            callBack: function (index, layero){
                var iframeWin = layero.find('iframe')[0];
                iframeWin.contentWindow.submitHandler();
            }
        };
        $.modal.openOptions(options);
    }

    //待本部门回复信件工单数据导出
    function exportReplyWaitExcel(){
        let areaNo = $('#areaNo').val();
        let exURL = "";
        if (areaNo === '510109'){
            exURL =  ctx + "system/lookup/mailReplyWait_gxq/export";
        }else{
            exURL =  ctx + "system/lookup/mailReplyWait/export";
        }
        let data = $("#post-form").serializeArray();
        $.modal.confirm("确定导出所有待本部门回复的信件工单吗？", function() {
            $.modal.loading("正在导出数据，请稍候...");
            $.post(exURL,data,function(result) {
                if (result.code == web_status.SUCCESS) {
                    $.table.refresh()
                    window.location.href = ctx + "common/download?fileName=" + encodeURI(result.msg) + "&delete=" + true;
                } else if (result.code == web_status.WARNING) {
                    $.modal.alertWarning(result.msg)
                } else {
                    $.modal.alertError(result.msg);
                }
                $.modal.closeLoading();
            });
        });
    }
    //催办派单
    function urgeTransact(){
        $("#smsInformModal").modal('show');
    }

    // 确认办理
    function ackTransact(){
        let row = $("#bootstrap-table").bootstrapTable('getSelections');
        var ids = "";
        var wfIds = "";
        var wfNos = "";
        debugger
        $.each(row,function(index){
            ids += row[index].myPkVal + ",";
            wfIds += row[index].WfId + ",";
            wfNos += row[index].myMwfNO + ",";
        })
        ids = ids.substr(0,ids.length - 1);
        wfIds = wfIds.substr(0,wfIds.length - 1);
        wfNos = wfNos.substr(0,wfNos.length - 1);
        let smsInform = $("#smsInform").val();
        debugger
        $.post(prefix + "/rCity/supUrgeTransact", {ids:ids,wfIds:wfIds,wfNos:wfNos,smsInform:smsInform},function (res) {
            if(res.code === 0){
                //清除弹窗原数据
                $('[name="smsInform"]').bootstrapSwitch('state', false);
                $("#smsInform").val(0);
                $("#smsInformModal").modal("hide");
                $.table.refresh()
                $.modal.msgSuccess("催办成功")
            }
        },"json")
    }

    //是否开启短信通知
    $('[name="smsInform"]').bootstrapSwitch({
        onText: "是",
        offText: "否",
        onColor: "success",
        offColor: "info",
        size: "mini",
        onSwitchChange: function (event, state) {
            if (state === true) {
                $("#smsInform").val(1);
            } else {
                $("#smsInform").val(0);
            }
        }
    });
</script>
</body>
</html>